package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/9/28 10:50
 * @description 541. 反转字符串 II
 */
public class Test541 {

    public static void main(String[] args) {


        System.out.println(reverseStr("abcdefgo", 3));


    }

    public static String reverseStr(String s, int k) {
        char[] cs = s.toCharArray();
        int n = s.length();
        for (int l = 0; l < n; l = l + 2 * k) {
            int r = l + k - 1;
            reverse(cs, l, Math.min(r, n - 1));
        }
        return String.valueOf(cs);
    }

    static void reverse(char[] cs, int l, int r) {
        while (l < r) {
            char c = cs[l];
            cs[l] = cs[r];
            cs[r] = c;
            l++;
            r--;
        }
    }

}
